<template>
	<view class="location-page">
		<!-- 地图组件 -->
		<hl-qqmap :locPath="'/static/images/ic_loc.png'"
				  :resetBtnPath="'/static/images/reset_loc.png'"
				  :showCitySearch="true"
				  :mapKey="'IS6BZ-KFVHJ-YLSFJ-KWTJ4-IEMNE-YBF2S'"
				  @addressUpdate="addressUpdate"></hl-qqmap>
				  
		<!-- 地址列表卡片 -->
		<view class="address-card" v-if="address_list && address_list.length > 0">
			<view class="card-header">
				<text class="header-title">位置列表</text>
				<text class="header-tips">点击选择位置</text>
			</view>
			
			<scroll-view class="address-list" scroll-y>
				<view 
					class="address-item" 
					v-for="(item, index) in address_list" 
					:key="index" 
					@tap="select_address(item)"
					:class="{'address-item-active': index === activeIndex}"
					@touchstart="activeIndex = index"
					@touchend="activeIndex = -1"
				>
					<view class="item-left">
						<text class="location-icon">📍</text>
					</view>
					<view class="item-content">
						<text class="item-title">{{item.title || item.name}}</text>
						<text class="item-address">{{item.address}}</text>
					</view>
					<view class="item-right">
						<text class="select-icon">选择</text>
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 无结果提示 -->
		<view class="empty-tips" v-else-if="address_list !== null && address_list.length === 0">
			<text class="tips-text">没有找到相关位置</text>
			<text class="sub-tips">请尝试其他关键词或移动地图</text>
		</view>
	</view> 
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				mapCenterLoc: null, //地图中心点位置
				address_list: '',
				activeIndex: -1, // 控制点击效果
			}
		},
		onLoad() {
			// 页面加载
		},
		
		methods: {
			addressUpdate: function(e){
				let result = e
				this.address_list = result.result;
			},
			select_address(e){				
				uni.$emit('select_address', e);
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	$primary-color: #F54242;
	$text-primary: #333333;
	$text-secondary: #666666;
	$text-light: #999999;
	$border-color: #EEEEEE;
	$bg-color: #F8F8F8;
	
	.location-page {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		background-color: $bg-color;
	}
	
	/* 地址列表卡片 */
	.address-card {
		margin: 24rpx;
		background-color: #FFFFFF;
		border-radius: 24rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
		overflow: hidden;
		
		.card-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 24rpx 32rpx;
			border-bottom: 1rpx solid $border-color;
			
			.header-title {
				font-size: 30rpx;
				font-weight: 600;
				color: $text-primary;
			}
			
			.header-tips {
				font-size: 24rpx;
				color: $text-light;
			}
		}
		
		.address-list {
			max-height: 600rpx;
		}
		
		.address-item {
			display: flex;
			align-items: center;
			padding: 24rpx 32rpx;
			border-bottom: 1rpx solid $border-color;
			transition: background-color 0.2s;
			
			&:last-child {
				border-bottom: none;
			}
			
			&-active {
				background-color: #F9F9F9;
			}
			
			.item-left {
				margin-right: 20rpx;
				
				.location-icon {
					font-size: 36rpx;
				}
			}
			
			.item-content {
				flex: 1;
				overflow: hidden;
				
				.item-title {
					display: block;
					font-size: 28rpx;
					color: $text-primary;
					font-weight: 500;
					margin-bottom: 8rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				
				.item-address {
					display: block;
					font-size: 24rpx;
					color: $text-light;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
			
			.item-right {
				margin-left: 20rpx;
				
				.select-icon {
					font-size: 24rpx;
					color: $primary-color;
					padding: 6rpx 16rpx;
					border: 1rpx solid $primary-color;
					border-radius: 24rpx;
				}
			}
		}
	}
	
	/* 空状态提示 */
	.empty-tips {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 60rpx 0;
		
		.tips-text {
			font-size: 30rpx;
			color: $text-secondary;
			margin-bottom: 16rpx;
		}
		
		.sub-tips {
			font-size: 26rpx;
			color: $text-light;
		}
	}
</style>